const { defineConfig } = require('@vue/cli-service');

const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const path = require('path');

module.exports = defineConfig({
  publicPath: process.env.VUE_APP_PUBLICPATH,  //文件路径，本地用'/',打包需改为'./'。由于路由地址为/dist/**(服务器二级目录）,所以正式的需要改为相对路径
  transpileDependencies: true,
  lintOnSave:false, //  关闭语法检查

  configureWebpack: {

    /*自动按需导入element*/
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
  },
  //less 全局变量
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "less",
      patterns: [
        // 全局变量路径
        path.resolve(__dirname, "./src/assets/css/global.less"),
      ],
    },
  },


  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0].title = process.env.VUE_APP_SYSTITLE
        return args
      })
  },
  // 代理服务器
  devServer: {
    port: 8602,
    proxy: {
      '/api': {
        target: process.env.VUE_APP_PATH,
        // target: 'http://192.168.102.32:19123/SchoolBus_API',
        // http://192.168.102.32:19123/SchoolBus_API
        pathRewrite: {
          '^/api': ''
        },
      }
    },
  },
})
